package edu.asu.sapa.ground.update;

import edu.asu.sapa.Planner;
import edu.asu.sapa.ground.MathForm;
import edu.asu.sapa.ground.State;

public class IntervalLoaderCC extends Load {

	public MathForm start;
	public MathForm duration;
	
	@Override
	// change context?
	public final boolean load(State s, Context c) {
		float t = start.value(s,c);
		float d = duration.value(s,c);
		float e = t + d;
		float a = s.time;
		boolean possible=true;
		if (t <= a) {
			for (Update u : contents) {
				possible&=u.startBefore(s, c, a);
			}
			s.events.add(c,this,UpdateWrapper.FinishAfter,e);
		} else {
//			for (Update u : contents) {
//				s.events.add(c,u,UpdateWrapper.StartBefore,t);
//				s.events.add(c,u,UpdateWrapper.FinishAfter,e);
//			}
			s.events.add(c,this,UpdateWrapper.StartBefore,t);
			s.events.add(c,this,UpdateWrapper.FinishAfter,e);
		}
		return possible;
	}
	
	public final boolean applicable(State s, Context c) {
		return true;
	}
	
	public String toString() {
		return "\t(over [" + start + ",^ " + duration + "]" + super.toString();
	}


}
